package org.tacademy.myrssfeeder;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RSSNewsItemView extends LinearLayout {

	private ImageView mIcon;
	private TextView mText01;
	private TextView mText02;
	private TextView mText03;
	private TextView mText04;
	private TextView mText05;
	
	public RSSNewsItemView(Context context) {
		super(context);
	}
	
	public RSSNewsItemView(Context context, RSSNewsItem aItem) {
		super(context);
		
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.listitem, this, true);
		
		mIcon = (ImageView)findViewById(R.id.iconItem);
		mIcon.setImageDrawable(aItem.getmIcon());
		
		mText01 = (TextView)findViewById(R.id.dataItem01);
		mText01.setText(aItem.getTitle());
		
		mText02 = (TextView)findViewById(R.id.dataItem02);
		mText02.setText(aItem.getPubDate());
		
		mText03 = (TextView)findViewById(R.id.dataItem03);
		
		String category = aItem.getCategory();
		if (category != null)
			mText03.setText(category);
		
		mText04 = (TextView)findViewById(R.id.dataItem04);
		mText04.setText(aItem.getDescription());
	}
	
	public void setIcon(Drawable icon){
		mIcon.setImageDrawable(icon);
	}
	
	public void setText(int index, String data){
		if(index == 0)
			mText01.setText(data);
		else if(index == 1)
			mText02.setText(data);
		else if(index == 2)
			mText03.setText(data);
		else if(index == 3)
			mText04.setText(data);
	}

}
